home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java Primer Plus
/
Java Primer Plus (Waite Group Proess)(1996).iso
/
chapter8
/
aline.java
< prev
next >
Wrap
Text File
|
1995-12-31
|
791b
|
43 lines
/* ------------ aline class -----------------*/
class aline { // a line class
int x[] = new int[2]; // endpoint x coordinates
int y[] = new int[2]; // endpoint y coordinates
int rx[] = new int[2]; // rotated endpoint x coordinates
int ry[] = new int[2]; // rotated endpoint y coordinates
int halfmax;
public aline (int maxval) {
halfmax = maxval/2;
y[0] = x[0] = (int)(Math.random() * halfmax);
y[1] = x[1] = -x[0];
}
void rotate (int angle) {
float radangle;
while (angle<0) angle += 360;
angle = angle%360;
radangle = angle*0.017453F;
for (int g=0;g<2;++g) {
rx[g] = (int)(Math.sin(radangle) * x[g]) + halfmax;
ry[g] = (int)(Math.cos(radangle) * y[g]) + halfmax;
}
}
}